package com.wonders.frame.repository;


/*import com.sun.xml.internal.bind.v2.model.core.ID;*/
import com.wonders.frame.entity.AuthAccountRole;
import com.wonders.frame.repository.core.CoreRepository;
/*import org.apache.poi.ss.formula.functions.T;*/
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

@Repository
public interface AuthAccountRoleRepository extends CoreRepository<AuthAccountRole> {

    List<AuthAccountRole> findByAccountId(String accountId);

    @Query("select ar.roleId from AuthAccountRole ar where ar.accountId=?1")
    List<String> findRoleIdByAccountId(String accountId);

    @Query("select ar.accountId from AuthAccountRole ar where ar.roleId=?1 and ar.removed=0")
    List<String> findAccountIdByRoleId(String RoleId);

    @Query(nativeQuery = true,value = "SELECT id FROM auth_account where removed=0 and id not in(SELECT account_id from auth_account_role where removed=0 and role_id=?1)")
    List<String> findOtheraccountByRoleId(String RoleId);

    @Query("select ar from AuthAccountRole ar where ar.accountId=?1 and ar.roleId=?2")
    AuthAccountRole findByAccountRoleId(String accountId,String roleId);


    @Transactional
    void deleteByAccountId(String accountId);

    @Transactional
    void deleteByAccountIdAndRoleId(String accountId, String roleId);

}
